﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pampa.CRUD.Configuration;
using Pampa.Grid.Core;
using Pampa.Grid.Core.Filters;
using Pampa.MVC.Fluent.Crud.Items;

namespace Pampa.MVC.Fluent.Grid
{
    public class QuickFilterBuilder<T>
    {
        protected readonly QuickFilterDefinition _qfDefinition;
        protected readonly string _quickfilterId;

        public QuickFilterBuilder(QuickFilterDefinition qfDefinition, string quickfilterId)
        {
            _qfDefinition = qfDefinition;
            _quickfilterId = quickfilterId;
        }

        public CheckBoxItemBuilder<T, T> CheckBox(string id = null)
        {
            var item = new CheckBoxItem();
            item.Id = id ?? _qfDefinition.Field;
            item.Enabled = true;
            _qfDefinition.Item = item;
            return new CheckBoxItemBuilder<T, T>(item);
        }

        public DateItemBuilder<T, T> DatePicker(string id = null)
        {
            var item = new DateItem();
            item.Id = id ?? _qfDefinition.Field;
            item.Enabled = true;
            _qfDefinition.Item = item;
            return new DateItemBuilder<T, T>(item);
        }

        public DateCombosItemBuilder<T, T> DateDropDowns(string id = null)
        {
            var item = new DateCombosItem();
            item.Id = id ?? _qfDefinition.Field;
            item.Enabled = true;
            _qfDefinition.Item = item;
            return new DateCombosItemBuilder<T, T>(item);
        }

        public EntityCheckListItemBuilder<T, T, IList<TEntity>> EntityCheckList<TEntity>(string id = null)
        {
            var item = new EntityCheckListItem();
            item.Id = id ?? _qfDefinition.Field;
            item.Enabled = true;
            item.EntityName = typeof(TEntity).AssemblyQualifiedName;
            _qfDefinition.Item = item;
            return new EntityCheckListItemBuilder<T, T, IList<TEntity>>(item, _quickfilterId);
        }

        public EntityComboItemBuilder<T, T, TEntity> EntityDropDown<TEntity>(string id = null)
        {
            var item = new EntityComboItem();
            item.Id = id ?? _qfDefinition.Field;
            item.Enabled = true;
            item.EntityName = typeof(TEntity).AssemblyQualifiedName;
            _qfDefinition.Item = item;
            return new EntityComboItemBuilder<T, T, TEntity>(item, _quickfilterId);
        }

        public EntitySelectorItemBuilder<T, T, TEntity> EntitySelector<TEntity>(string id = null)
        {
            var item = new EntitySelectorItem();
            item.Id = id ?? _qfDefinition.Field;
            item.Enabled = true;
            item.EntityName = typeof(TEntity).AssemblyQualifiedName;
            _qfDefinition.Item = item;
            return new EntitySelectorItemBuilder<T, T, TEntity>(item, _quickfilterId);
        }

        public StaticComboItemBuilder<T, T> DropDown(string id = null)
        {
            var item = new StaticComboItem();
            item.Id = id ?? _qfDefinition.Field;
            item.Enabled = true;
            _qfDefinition.Item = item;
            return new StaticComboItemBuilder<T, T>(item);
        }

        public TextItemBuilder<T, T> Text(string id = null)
        {
            var item = new TextItem();
            item.Id = id ?? _qfDefinition.Field;
            item.Enabled = true;
            _qfDefinition.Item = item;
            return new TextItemBuilder<T, T>(item);
        }
    }
}
